package com.four.controller;

import com.four.pojo.User;
import com.four.service.IUserService;
import com.four.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpSession;

/**
 * @author 王森
 * @create 2021-10-29 22:19
 */
@Controller
public class UserController {

    @Autowired
    @Qualifier("userServiceImpl")
    private UserServiceImpl userService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    private String login(User user , Model model, HttpSession session){
        User user1=userService.login(user);
        if(user1!=null && !"".equals(user1)){
                session.setAttribute("username",user1.getUsername());
                session.setAttribute("user",user1);
                return "index.jsp";
        }else {
            model.addAttribute("err","密码或用户名错误");
            return "login.jsp";
        }
    }




}
